/*!
 * ThreeTimesError - Error handling made easy. What, where and how? You decide.
 * Version: 20120409_1517
 * http://code.google.com/p/threetimeserror/
 *
 * Copyright 2012 by Stefan Matsson
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 */ 
;(function(tte) {
  /*jshint noarg:true, noempty:true, eqeqeq:true, loopfunc:true, bitwise:true, strict:true, undef:true, curly:true, browser:true, maxerr:50, validthis:true */
	"use strict";	
	var has = Object.prototype.hasOwnProperty;
	
	// Http get reporter
	function httpGetReporter(options) {
		this.options = options;
	}
	httpGetReporter.prototype.run = function(obj) {
		var s, i, qs = [], d = document, es, rand, token;
		if(!this.options.url) { return; }
		token = typeof this.options.token === "function" ? 
				this.options.token() :
				this.options.token;
		rand = this.options.randomizer;
		
		s = d.createElement("script");
		s.src = this.options.url;
		s.src = s.src.indexOf("?") > -1 ? s.src += "&" : s.src += "?";
		for(i in obj) {
			if(!has.call(obj, i)) { continue; }
			qs.push(i + "=" + encodeURIComponent(obj[i]));
		}
		
		if(token) { qs.push("token=" + encodeURIComponent(token)); }
		qs.push("v=" + encodeURIComponent(+new Date()));
		
		s.src += qs.join("&");
		es = d.getElementsByTagName("script")[0];
		es.parentNode.insertBefore(s, es);
		setTimeout(function() { s.parentNode.removeChild(s); }, 20);
	};
	
	// Add to object
	tte.reporters.httpGet = httpGetReporter;
	
}(window.TTE));